package love.yuanmengrobot.als.business.dao.impl;
/*
 *   @Studio:CHJY · 源梦科技
 *   @Author:lzl
 *   @Ide:IntelliJ IDEA
 *   @Creation time:2021/6/9 23:54
 */

import love.yuanmengrobot.als.business.dao.GetTrainPlan;
import love.yuanmengrobot.als.business.javaBean.Alstrainplan;
import love.yuanmengrobot.als.utilPublic.JdbcUtil;
import love.yuanmengrobot.als.utilPublic.SqlString;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class GetTrainPlanImpl implements GetTrainPlan {
//    @Override
//    public List<Alstrainplan> getTrainPlan(String majorId) {
//        Connection conn=null;
//        PreparedStatement ps=null;
//        ResultSet rs=null;
//        List<Alstrainplan> trainPlanList=new ArrayList<>();
//        try {
//            conn= JdbcUtil.getConnection();
//            ps=conn.prepareStatement(SqlString.selectTrainPlan(majorId));
//            rs=ps.executeQuery();
//            while(rs.next()){
//                Alstrainplan trainPlan = new Alstrainplan();
//                trainPlan.setTrainplanId(rs.getString("trainplan_id"));
//                trainPlan.setMajorId(rs.getString("major_id"));
//                trainPlan.setGrade(rs.getString("grade"));
//                trainPlan.setDisciplineBasis(rs.getString("discipline_basis"));
//                trainPlan.setGeneralElective(rs.getString("general_elective"));
//                trainPlan.setGeneralRequired(rs.getString("general_required"));
////                System.out.println(rs.getString("limite_credit")+"aaaaaaaaaaaaaaaaaaaaa");
//                trainPlan.setLimiteCredit(rs.getString("limite_credit"));
//                trainPlan.setOptionalCredit(rs.getString("optional_credit"));
//                trainPlan.setPracticeLink(rs.getString("practice_link"));
//                trainPlan.setProfessionalRequired(rs.getString("professional_required"));
//                trainPlanList.add(trainPlan);
//            }
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }finally {
//            JdbcUtil.close(rs,ps,conn);
//        }
//        return trainPlanList;
//    }
@Override
public Alstrainplan getTrainPlan(String majorId) {
    Connection conn=null;
    PreparedStatement ps=null;
    ResultSet rs=null;
    Alstrainplan trainPlan =null;
    try {
        conn= JdbcUtil.getConnection();
        ps=conn.prepareStatement(SqlString.selectTrainPlan(majorId));
        rs=ps.executeQuery();
        while(rs.next()){
            trainPlan = new Alstrainplan();
            trainPlan.setTrainplanId(rs.getString("trainplan_id"));
            trainPlan.setMajorId(rs.getString("major_id"));
            trainPlan.setGrade(rs.getString("grade"));
            trainPlan.setDisciplineBasis(rs.getString("discipline_basis"));
            trainPlan.setGeneralElective(rs.getString("general_elective"));
            trainPlan.setGeneralRequired(rs.getString("general_required"));
//                System.out.println(rs.getString("limite_credit")+"aaaaaaaaaaaaaaaaaaaaa");
            trainPlan.setLimiteCredit(rs.getString("limite_credit"));
            trainPlan.setOptionalCredit(rs.getString("optional_credit"));
            trainPlan.setPracticeLink(rs.getString("practice_link"));
            trainPlan.setProfessionalRequired(rs.getString("professional_required"));
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }finally {
        JdbcUtil.close(rs,ps,conn);
    }
    return trainPlan;
}
}
